package com.xuchaotong.label;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;

public class User implements FactoryBean, InitializingBean, ApplicationContextAware,ApplicationListener<ContextRefreshedEvent> {
    private String name;
    private String email;

    public User() {
        System.out.println("This is user construct...");
    }

    public User(String arg) {
        if (arg == null) {
            System.out.println("我是有參的构造方法");
        }
    }

    @Override
    public Object getObject() throws Exception {

        System.out.println("工厂方法");
        return new String("name is : " + name + ", email is : " + email);
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("属性设置完成");
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("设置容器对象。。。");
    }

    @Override
    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
        System.out.println("容器初始化完成了...");
    }

    @Override
    public boolean isSingleton() {
        return true;
    }

    @Override
    public Class<?> getObjectType() {
        return String.class;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }
}
